﻿#region Imports
using System;
using System.Globalization;
using System.Windows.Data;
using CommonUtilities.Extensions;
#endregion Imports

namespace BulkRenamer.App.WPF.Converters
{
    public class CountConverter : IValueConverter
    {
        const string defaultValue = "--";

        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                int source = (int)value;
                return source > 0 ? source.ToString() : defaultValue;
            }
            catch (Exception)
            {
                return defaultValue;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value.IsNumeric() ? (int)value : 0;
        }
        #endregion IValueConverter Members
    }
}
